package com.gerenboke.controller;

import com.gerenboke.domain.ResponseResult;
import com.gerenboke.domain.entity.Menu;
import com.gerenboke.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @GetMapping("/list")
    public ResponseResult selectMenuList(String status,String menuName) {
        return menuService.selectMenu(status,menuName);
    }

    @PostMapping()
    public ResponseResult saveMenu(@RequestBody Menu menu) {
        boolean save = menuService.save(menu);
            return ResponseResult.okResult();
    }

    @GetMapping("/{id}")
    public ResponseResult selectMenu(@PathVariable Long id){
        Menu menu = menuService.getById(id);
        return ResponseResult.okResult(menu);
    }

    @PutMapping("")
    public ResponseResult updateMenu(@RequestBody Menu menu){
        return menuService.updateMenu(menu);
    }

    @DeleteMapping("/{menuId}")
    public ResponseResult deleteMenu(@PathVariable Long menuId){
        return menuService.deleteMenu(menuId);
    }

    @GetMapping("/treeselect")
    public ResponseResult selectMenuList(){
        return menuService.selectMenuListr();
    }

    @GetMapping("/roleMenuTreeselect/{id}")
    public ResponseResult roleMenuTreeselect(@PathVariable Long id){
        return menuService.roleMenuTreeselect(id);
    }
}
